<?php

/*
 *
 *function to send user email
 */

function mailUser($userEmailaddress){
    $inserVCode = uniqueVCodeGen();
$to      = $userEmailaddress;
$subject = 'Freecycle Activation code';
$message = 'activation code: ' . $inserVCode . "\r\n" .
'hello new user please use this code on the' . "\r\n" .
'account activation page to start posting items to be recycled' . "\r\n" .
'and to recycle item you might find useful from other members';
$from = 'abscoral@live.co.uk';// should change to include a header for the 
//email

mail($to, $subject, $message, $from);
}

function generateVCode(){
    $alphabet = array('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z');
    $ranCode = '';
    for ($index = 0; $index < 5; $index++) {
      $ranCode = $ranCode . $alphabet[rand(0, 25)];
    }
    return $ranCode;
}

function uniqueVCodeGen(){
    require_once 'C:\xampp\htdocs\GreenwichFreecycle\include\greenFreeDb.php';
    
    $notUnique = TRUE;
    while($notUnique){
        $uniqueVCode = generateVCode();
        $notUnique = isVCodeAlreadyStoredDb($uniqueVCode);
    }
    return $uniqueVCode;
}
?>
